<?php

use App\Http\Controllers\Admin\Dashboard;
use App\Http\Controllers\Admin\UserController;
use App\Http\Controllers\AuthController;
use App\Livewire\Counter;
use App\Models\User;
use Illuminate\Support\Facades\Route;

Route::get('/', function () {
    return view('welcome');
});

Route::middleware('guest')->group(function () {
    Route::get('admin/login', [AuthController::class, 'login'])->name('admin.login');
    Route::post('admin/login', [AuthController::class, 'doLogin'])->name('admin.login.post');
    Route::get('admin/register', [AuthController::class, 'register'])->name('admin.register');
    Route::post('admin/register', [AuthController::class, 'doRegister'])->name('admin.register.post');
});

Route::middleware(['auth'])->prefix('admin')->group(function () {
    Route::get('/', [Dashboard::class, 'index'])->name('admin.dashboard');
    Route::post('logout', [AuthController::class, 'logout'])->name('admin.logout');
    Route::get('/users', [UserController::class, 'index'])->can('list', User::class)->name('admin.user.list'); // 用户列表
//    Route::get('/users/create', [UserController::class, 'create'])->can('create', User::class)->name('admin.user.create'); // 创建用户
    Route::get('/users/create', \App\Livewire\Admin\User\Create::class)->can('create', User::class)->name('admin.user.create'); // 创建用户
//    Route::get('/users/{user}/edit', [UserController::class, 'update'])->can('update', User::class)->name('admin.user.update'); // 创建用户
    Route::get('/users/{user}/edit', \App\Livewire\Admin\User\Update::class)->can('update', User::class)->name('admin.user.update'); // 创建用户
    Route::delete('/users/{user}', [UserController::class, 'delete'])->can('delete', User::class)->name('admin.user.delete');
    Route::get('/permissions', [\App\Http\Controllers\PermissionController::class, 'index'])->can('list', \Spatie\Permission\Models\Permission::class)->name('admin.permission.list'); // 用户列表
    Route::get('/permissions/create', \App\Livewire\Admin\Permission\Create::class)->can('create', \Spatie\Permission\Models\Permission::class)->name('admin.permission.create'); // 新增权限
    Route::get('/permissions/{permission}/edit', \App\Livewire\Admin\Permission\Update::class)->can('update', \Spatie\Permission\Models\Permission::class)->name('admin.permission.update'); // 编辑权限
    Route::delete('/permissions/{permission}', [\App\Http\Controllers\PermissionController::class, 'delete'])->can('delete', \Spatie\Permission\Models\Permission::class)->name('admin.permission.delete');
    Route::get('/roles', [\App\Http\Controllers\RoleController::class, 'index'])->can('list', \Spatie\Permission\Models\Role::class)->name('admin.role.list'); // 角色列表
    Route::get('/roles/create', \App\Livewire\Admin\Role\Create::class)->can('create', \Spatie\Permission\Models\Role::class)->name('admin.role.create'); // 新增角色
    Route::get('/roles/{role}/edit', \App\Livewire\Admin\Role\Update::class)->can('update', \Spatie\Permission\Models\Role::class)->name('admin.role.update'); // 编辑角色
    Route::delete('/roles/{role}', [\App\Http\Controllers\RoleController::class, 'delete'])->can('delete', \Spatie\Permission\Models\Role::class)->name('admin.role.delete');
});
